package com.wanjia.seal.manager.controller;

import com.alibaba.fastjson.JSONObject;
import com.wanjia.seal.manager.annotation.LoginToken;
import com.wanjia.seal.manager.controller.ex.DataNotFoundException;
import com.wanjia.seal.manager.entity.datamodilog;
import com.wanjia.seal.manager.entity.datamodilogVO;
import com.wanjia.seal.manager.mapper.DatamodilogMapper;
import com.wanjia.seal.manager.utils.JsonResult;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Arrays;
import java.util.List;

@Controller
@RequestMapping("/api")
@Api(tags = "印模数据库修改日志表查询")
public class datamodilogController extends BaseController{
    @Autowired
    DatamodilogMapper datamodilogMapper;

    @ResponseBody
    @PostMapping("/getDatamodilog")
    @LoginToken
    public JsonResult<Object> findAllDatamodilog(@RequestBody datamodilog datamodilog, String startTime, String endTime, Integer pageNum, Integer pageSize){
        String Account = datamodilog.getAccount();
        Integer dummy = datamodilog.getDummy();
        String modiOper = datamodilog.getModiOper();
        String operID = datamodilog.getOperID();
        String BANK = datamodilog.getBANK();
        List<String> list = Arrays.asList(BANK.split(","));
        if (startTime==null){
            startTime ="1988-01-01";
        }
        if (endTime==null){
            endTime="2099-01-01";
        }
        if (dummy==null){
            dummy=1;
        }
        if (pageNum != null){
            List<datamodilogVO> result = datamodilogMapper.findBydatamodilog(Account, dummy, modiOper, operID, list, startTime, endTime, pageNum, pageSize);
            List<datamodilogVO> result2 = datamodilogMapper.findBydatamodilogs(Account, dummy, modiOper, operID, list, startTime, endTime);
            int size = result2.size();
            JSONObject jsonObject=new JSONObject();
            jsonObject.put("total",size);
            jsonObject.put("datamodilog",result);
            return new JsonResult<>(OK,jsonObject);
        }else{
            List<datamodilogVO> result = datamodilogMapper.findBydatamodilogs(Account, dummy, modiOper, operID, list, startTime, endTime);
            int size = result.size();
            JSONObject jsonObject=new JSONObject();
            jsonObject.put("total",size);
            jsonObject.put("datamodilog",result);
            return new JsonResult<>(OK,jsonObject);
        }

    }
}
